package com.zwj.dao.impl;

import com.mysql.cj.util.DnsSrv;
import com.zwj.bean.User;
import com.zwj.dao.BaseDao;
import com.zwj.dao.UserDao;

/**
 * @author zwj
 * @create 2021-05-12-16:31
 */
public class UserDaoImpl extends BaseDao implements UserDao {
    /**
     * 通过用户名查询用户
     * @param username
     * @return
     */
    @Override
    public User queryUserByUsername(String username) {
        String sql = "select `id`,`username`,`password`,`email` from t_user where username = ?";
        return queryForOne(User.class,sql,username);
    }

    /**
     * 通过用户名和密码查询用户
     * @param username
     * @param password
     * @return
     */
    @Override
    public User queryUserByUsernameAndPassword(String username, String password) {
        String sql = "select `id`,`username`,`password`,`email` from t_user where username = ? and password = ?";
        return queryForOne(User.class,sql,username,password);
    }

    /**
     * 保存用户到数据库
     * @param user
     * @return
     */
    @Override
    public int saveUser(User user) {
        String sql = "insert into t_user(`username`,`password`,`email`) values(?,?,?)";
        return update(sql,user.getUsername(),user.getPassword(),user.getEmail());
    }
}
